import * as echarts from 'echarts'

function create(name, xData, distribution, distributionRatio){
    const chart = echarts.init(document.querySelector(name));

    let option = {
        // Make gradient line here
        visualMap: [
            {
                show: false,
                type: 'continuous',
                seriesIndex: 0,
                min: 0,
                max: 400,
            },
            {
                show: false,
                type: 'continuous',
                seriesIndex: 1,
                dimension: 0,
                min: 0,
                max: xData.length - 1,

            }
        ],
        textStyle: {
            color: 'white' // 设置标题文字颜色为红色
        },
        title: [
            {
                left: 'center',
                text: '体素值分布',
                color: 'white',
                textStyle: {
                    color: 'white' // 设置标题文字颜色为红色
                },
            },
            {
                top: '55%',
                left: 'center',
                text: '体素值分布比例',
                textStyle: {
                    color: 'white' // 设置标题文字颜色为红色
                },
            }
        ],
        tooltip: {
            trigger: 'axis'
        },
        xAxis: [
            {
                data: xData
            },
            {
                data: xData,
                gridIndex: 1
            }
        ],
        yAxis: [
            {},
            {
                gridIndex: 1
            }
        ],
        grid: [
            {
                bottom: '60%'
            },
            {
                top: '60%'
            }
        ],
        series: [
            {
                type: 'line',
                showSymbol: false,
                data: distribution
            },
            {
                type: 'line',
                showSymbol: false,
                data: distributionRatio,
                xAxisIndex: 1,
                yAxisIndex: 1
            }
        ]
    };

    chart.setOption(option)
}

export default {
    create
}